﻿#ifndef __HTML_TREE_H__
#define __HTML_TREE_H__

using namespace std;
using namespace htmlcxx;

class CHtmlTree
{
public:
	typedef tree<HTML::Node>::iterator			HT_Iterator;
	typedef tree<HTML::Node>::sibling_iterator	HT_Sibling_Iterator;

public:
	CHtmlTree(void);
	~CHtmlTree(void);

public:
	//分析Html
	bool Parse(const string& rstrHtml);

public:
	inline HT_Iterator Begin()
	{
		return m_kHtmlDom.begin();
	}
	inline HT_Iterator End()
	{
		return m_kHtmlDom.end();
	}

	inline const HT_Sibling_Iterator ChildBegin(HT_Iterator iter) const
	{
		return iter.begin();
	}
	inline const HT_Sibling_Iterator ChildEnd(HT_Iterator iter) const
	{
		return iter.end();
	}

public:
	//从iter开始按tag类型查找标志块
	HT_Iterator GetNextTag(HT_Iterator iterBegin,HT_Iterator iterEnd,const char* pszTag);
	//从iter开始按tag属性查找标志块
	HT_Iterator GetNextTag(HT_Iterator iterBegin,HT_Iterator iterEnd,const char* pszTag,const string& rstrAttr,const char* pszValue);

	//在iterParent的子列下，从iter开始按tag类查找标志块
	HT_Sibling_Iterator GetNextChildTag(HT_Sibling_Iterator iterBegin,HT_Sibling_Iterator iterEnd,const char* pszTag);
	//在iterParent的子列下，从iter开始按tag属性查找标志块
	HT_Sibling_Iterator GetNextChildTag(HT_Sibling_Iterator iterBegin,HT_Sibling_Iterator iterEnd,const char* pszTag,const string& rstrAttr,const char* pszValue);

private:
	tree<HTML::Node> m_kHtmlDom;
};

#endif //__HTML_TREE_H__